package com.lizhi.yun.core.treat;/**
 * @program: hbsf_yun
 * @name MsbTreatHandler
 * @description: 训练信息
 * @author: lizhi
 * @create: 2021-12-31 13:28
 */

import com.lizhi.common.yun.entity.RpcServicePOJO;
import com.lizhi.common.yun.enums.HeartBeartEnum;
import com.lizhi.utils.StringUtils;
import com.lizhi.utils.json.SamJsonUtil;
import com.lizhi.yun.db.msb.dao.MsbTreatRecordDao;
import com.lizhi.yun.db.msb.entity.MsbTreatRecordEntity;
import com.lizhi.yun.deploy.NewBaseHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 *@program: hbsf_yun
 *@name MsbTreatHandler
 *@description: 训练信息
 *@author: lizhi
 *@create: 2021-12-31 13:28
 */
@Slf4j
@Service
public class MsbTreatHandler extends NewBaseHandler {

    @Resource
    private MsbTreatRecordDao msbTreatRecordDao;

    public String recvTreat(String json){
        RpcServicePOJO rpcServicePOJO = new RpcServicePOJO();
        try {
            MsbTreatRecordEntity msbTreatRecordEntity = SamJsonUtil.toObject(json, MsbTreatRecordEntity.class);
            MsbTreatRecordEntity treatRecordEntity = msbTreatRecordDao.selectById(msbTreatRecordEntity.ptId, msbTreatRecordEntity.hospitalId, msbTreatRecordEntity.hospitalSystemId);
            if (StringUtils.isEmpty(treatRecordEntity)){
                msbTreatRecordEntity.lid = StringUtils.newId();
                msbTreatRecordDao.insertRecord(msbTreatRecordEntity);
            } else {
                msbTreatRecordDao.updateByIdSelective(msbTreatRecordEntity);
            }
            rpcServicePOJO.setErrorCode(HeartBeartEnum.HEART_BEART_000000.getEnValue());
            rpcServicePOJO.setMessage(HeartBeartEnum.HEART_BEART_000000.getEnName());
        } catch (Exception e){
            log.error("接收同步的治疗信息出现异常:{}", e.getMessage());
        }
        return SamJsonUtil.toJson(rpcServicePOJO);
    }
}
